package com.xyz.apis.common.utils;


import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;

import java.io.Serializable;

/***
 */
@ApiModel(description = "返回接口类")
public class Rest<T> implements Serializable{

	@ApiModelProperty(value = "状态码 0成功")
	private int code;

	@ApiModelProperty(value = "返回对象")
	private T data;

	@ApiModelProperty(value = "结果信息")
	private String msg;

	public Rest(){
	}

	public Rest(T data) {
		this.data = data;
		this.code = MsgCode.SUCCESS;
	}
	public Rest(T data,int code) {
		this.data = data;
		this.code = code;
	}

	public static Rest ok() {
		Rest restMessage = new Rest();
		restMessage.setCode(MsgCode.SUCCESS);
		restMessage.setMsg("");
		return restMessage;
	}

	public static Rest ok(Object data) {
		Rest restMessage = new Rest();
		restMessage.setCode(MsgCode.SUCCESS);
		restMessage.setData(data);
		restMessage.setMsg("");
		return restMessage;
	}

	public static Rest ok(Object data,int code) {
		Rest restMessage = new Rest();
		restMessage.setCode(code);
		restMessage.setData(data);
		restMessage.setMsg("");
		return restMessage;
	}

	public static Rest ok(Object data,int code,String msg) {
		Rest restMessage = new Rest();
		restMessage.setCode(code);
		restMessage.setData(data);
		restMessage.setMsg(msg);
		return restMessage;
	}

	public static Rest ok(String msg) {
		Rest restMessage = new Rest();
		restMessage.setCode(MsgCode.SUCCESS);
		restMessage.setMsg(msg);
		return restMessage;
	}

	public static Rest ok(int code, String msg) {
		Rest restMessage = new Rest();
		restMessage.setCode(code);
		restMessage.setMsg(msg);
		return restMessage;
	}

	public static Rest error() {
		Rest restMessage = new Rest();
		restMessage.setCode(MsgCode.ERROR);
		restMessage.setMsg(MsgCode.ERRORMSG);
		return restMessage;
	}

	public static Rest error(String msg) {
		Rest restMessage = new Rest();
		restMessage.setCode(MsgCode.ERROR);
		restMessage.setMsg(msg);
		return restMessage;
	}

	public static Rest error(int code, String msg) {
		Rest restMessage = new Rest();
		restMessage.setCode(code);
		restMessage.setMsg(msg);
		return restMessage;
	}


	public int getCode() {
		return code;
	}

	public void setCode(int code) {
		this.code = code;
	}

	public T getData() {
		return data;
	}

	public void setData(T data) {
		this.data = data;
	}

	public String getMsg() {
		return msg;
	}

	public void setMsg(String msg) {
		this.msg = msg;
	}
}
